package com.ruoyi.project.yingyu.bookcatelog.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.framework.web.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.yingyu.bookcatelog.mapper.BookCatelogMapper;
import com.ruoyi.project.yingyu.bookcatelog.domain.BookCatelog;
import com.ruoyi.project.yingyu.bookcatelog.service.IBookCatelogService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 单词目录Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-03-23
 */
@Service
public class BookCatelogServiceImpl implements IBookCatelogService 
{
    @Autowired
    private BookCatelogMapper bookCatelogMapper;

    /**
     * 查询单词目录
     * 
     * @param id 单词目录ID
     * @return 单词目录
     */
    @Override
    public BookCatelog selectBookCatelogById(Long id)
    {
        return bookCatelogMapper.selectBookCatelogById(id);
    }

    /**
     * 查询单词目录列表
     * 
     * @param bookCatelog 单词目录
     * @return 单词目录
     */
    @Override
    public List<BookCatelog> selectBookCatelogList(BookCatelog bookCatelog)
    {
        return bookCatelogMapper.selectBookCatelogList(bookCatelog);
    }

    /**
     * 新增单词目录
     * 
     * @param bookCatelog 单词目录
     * @return 结果
     */
    @Override
    public int insertBookCatelog(BookCatelog bookCatelog)
    {
        return bookCatelogMapper.insertBookCatelog(bookCatelog);
    }

    /**
     * 修改单词目录
     * 
     * @param bookCatelog 单词目录
     * @return 结果
     */
    @Override
    public int updateBookCatelog(BookCatelog bookCatelog)
    {
        return bookCatelogMapper.updateBookCatelog(bookCatelog);
    }

    /**
     * 删除单词目录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBookCatelogByIds(String ids)
    {
        return bookCatelogMapper.deleteBookCatelogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除单词目录信息
     * 
     * @param id 单词目录ID
     * @return 结果
     */
    @Override
    public int deleteBookCatelogById(Long id)
    {
        return bookCatelogMapper.deleteBookCatelogById(id);
    }

    /**
     * 查询单词目录树列表
     * 
     * @return 所有单词目录信息
     */
    @Override
    public List<Ztree> selectBookCatelogTree()
    {
        List<BookCatelog> bookCatelogList = bookCatelogMapper.selectBookCatelogList(new BookCatelog());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (BookCatelog bookCatelog : bookCatelogList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(bookCatelog.getId());
            ztree.setpId(bookCatelog.getPid());
            ztree.setName(bookCatelog.getName());
            ztree.setTitle(bookCatelog.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
